package com.example.anew.journey.mynewjourney.firstchangelogic.FirstChangeMain.adpater;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.anew.journey.mynewjourney.R;
import com.example.anew.journey.mynewjourney.inteface.OnRecyclerViewItemClickListener;

/**
 * 杭州惟君医疗科技有限公司17
 * Created by 20433 on 2018/3/13
 */

public class MyLeftAdapter extends RecyclerView.Adapter<MyLeftAdapter.ViewHolder> implements View.OnClickListener{
    private OnRecyclerViewItemClickListener mOnItemClickListener = null;
    private String[] arr = new String[]{"设备","设置"};
    private int[] myarr = new int[]{R.drawable.shebei,R.drawable.settings};
    public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
       View view  =  View.inflate(parent.getContext(), R.layout.my_left_item_selector,null);
        // 实例化viewholder
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }
    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.iv_my_decices.setImageResource(myarr[position]);
        holder.tv_name.setText(arr[position]);
        holder.rl_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(mOnItemClickListener != null ){
                    mOnItemClickListener.onItemFirstButtonClick(view,position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return arr.length;
    }

    @Override
    public void onClick(View view) {
        if(mOnItemClickListener != null ){
            mOnItemClickListener.onItemClick(view);
        }
    }
    public static class ViewHolder extends RecyclerView.ViewHolder {

        private final ImageView iv_my_decices;
        private final TextView tv_name;
        private final ImageView iv_next_stop;
        private final RelativeLayout rl_item;

        public ViewHolder(View itemView) {
            super(itemView);
            iv_my_decices = itemView.findViewById(R.id.my_left_item_selector_iv_my_decices);
            tv_name = itemView.findViewById(R.id.my_left_item_selector_tv_name);
            iv_next_stop = itemView.findViewById(R.id.my_left_item_selector_iv_next_stop);
            rl_item = itemView.findViewById(R.id.my_left_item_selector_rl_item);
        }
    }
}
